#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
    int hour = 0;
    int min = 0;
    scanf("%d:%d", &hour, &min);
    if (hour <= 11)
    {
        printf("%d:%d ", hour, min);
        printf("AM\n");
    }
    else if (hour == 12)
    {
        printf("%d:%d ", hour, min);
        printf("PM\n");
    }
    else
    {
        int newhour = 12 - (24 - hour);
        printf("%d:%d ", newhour, min);
        printf("PM\n");
    }
    return 0;
}